package com.jsonal.controller;

import com.jsonal.entity.VideoBean;
import com.jsonal.form.VideoForm;
import com.jsonal.service.VideoService;
import com.jsonal.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: jsonal
 * @Description:
 * @Date: 2020/12/29 14:26
 * @Version: 1.0
 */
@RestController
public class VideoController extends BaseController {

    @Autowired
    private VideoService videoService;

    @PostMapping("/managers/addOrUpdateVideo")
    public Result addOrUpdate(@RequestBody VideoForm videoForm) {
        VideoBean videoBean = new VideoBean();
        this.setFormToBean3(videoForm, videoBean);
        return videoService.addOrUpdate(videoBean);
    }

    @GetMapping("/managers/getVideoByPage")
    public Result getVideoByPage(VideoForm videoForm) {
        VideoBean videoBean = new VideoBean();
        this.setFormToBean3(videoForm, videoBean);
        return videoService.getVideoByPage(videoBean);
    }

    @GetMapping("/api/getVideoList")
    public Result getVideoList(VideoForm videoForm) {
        VideoBean videoBean = new VideoBean();
        this.setFormToBean3(videoForm, videoBean);
        return videoService.getVideoByPage(videoBean);
    }

    @PostMapping("/managers/deleteVideoById/{id}")
    public Result deleteVideoById(@PathVariable String id) {
        if ("".equals(id) || null == id) {
            return new Result(false, "id不能为空！");
        }
        return videoService.deleteVideoById(id);
    }

}
